function i(i) {
    return i && i.__esModule ? i : {
        default: i
    };
}

function e(i, e, t) {
    return e in i ? Object.defineProperty(i, e, {
        value: t,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : i[e] = t, i;
}

function t(i, e) {
    if (!(i instanceof e)) throw new TypeError("Cannot call a class as a function");
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var a = function() {
    function i(i, e) {
        for (var t = 0; t < e.length; t++) {
            var a = e[t];
            a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), 
            Object.defineProperty(i, a.key, a);
        }
    }
    return function(e, t, a) {
        return t && i(e.prototype, t), a && i(e, a), e;
    };
}(), n = i(require("../../utils/util")), o = i(require("../../utils/config")), d = i(require("../../public/utils/authorize")), s = require("../../public/pages/signin-page/checkIfNeedSignin"), r = i(require("../editor/section-form/section-form")), c = i(require("../../utils/api2")), u = function() {
    function i(e) {
        var a = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
        t(this, i), Object.assign(this, {
            options: a
        }), this.page = e;
        var n = void 0;
        wx.getSystemInfo({
            success: function(i) {
                n = i.windowWidth, e.setData({
                    windowWidth: n,
                    swiper: []
                });
            }
        }), this.__init();
    }
    return a(i, [ {
        key: "__init",
        value: function() {
            this.options.data && this.__initData(), this.__methods();
        }
    }, {
        key: "__initData",
        value: function() {
            var i = this.options.scope || "editorContent", t = this.options.data;
            if (this._data = {}, !n.default.isEmptyObject(t)) for (var a in t) t.hasOwnProperty(a) && "function" != typeof t[a] && (this._data[a] = t[a]);
            this.page.setData(e({}, "" + i, this._data));
        }
    }, {
        key: "__methods",
        value: function() {
            var i = this;
            this.page.navigatImageLink = this.navigatImageLink.bind(this), this.page.navigatLinkLink = this.navigatLinkLink.bind(this), 
            this.page.openLocation = this.openLocation.bind(this), this.page.imageLoad = this.imageLoad.bind(this), 
            this.page.playVideo = this.playVideo.bind(this), this.page.videoScreenchange = this.videoScreenchange.bind(this), 
            this.page.$$redirectToNavigation = this.$$redirectToNavigation.bind(this), this.page.$$redirectToDetail = this.$$redirectToDetail.bind(this), 
            this.page.$$makePhoneCall = this.$$makePhoneCall.bind(this), this.page.redirectToBargainingList = this.redirectToBargainingList.bind(this), 
            this.page.redirectToPayment = this.redirectToPayment.bind(this), this.page.redirectToCouponList = this.redirectToCouponList.bind(this), 
            this.page.redirectToGrouponList = this.redirectToGrouponList.bind(this), this.page.redirectToSearch = this.redirectToSearch.bind(this), 
            this.page.viewBargaining = this.viewBargaining.bind(this), this.page.viewCard = this.viewCard.bind(this), 
            this.page.viewPanorama = this.viewPanorama.bind(this), this.page.viewGroupon = this.viewGroupon.bind(this), 
            this.page.showProductBar = this.showProductBar.bind(this), this.page.$$gotoRaffleList = this.$$gotoRaffleList.bind(this), 
            Object.assign(this.page, r.default), this.page.$addListener("form:submit", function(e) {
                var t = e.formid, a = e.datas, n = e.fields;
                e.route === i.page.route && (a = a.map(function(i) {
                    return i.value = i.value || "", i;
                }), i.$$submitForm({
                    formid: t,
                    datas: a
                }).then(function() {
                    i.page.$$clearForm(n);
                }));
            });
        }
    }, {
        key: "$$submitForm",
        value: function(i) {
            var e = i.formid, t = i.datas, a = this.page.data.sharePluginData, o = a.sid, d = a.navid, s = a.cid, r = a.id, u = a.caseid, l = a.modid, g = a.model, h = {
                appid: getApp().globalData.appid,
                formid: e,
                sid: +o,
                navid: d || 0,
                cid: s || r || u || 0,
                from: this.$$getFormFrom(l, g),
                datas: t
            };
            return c.default.site.form.submit({
                data: h,
                desc: "提交"
            }).then(function(i) {
                return n.default.qAlert("表单提交成功"), "";
            }).catch(function() {
                return n.default.qAlert("表单提交失败，请重新提交"), Promise.reject();
            });
        }
    }, {
        key: "$$getFormFrom",
        value: function(i, e) {
            return 0 == +i || 1 == +i ? 1 : 2 == +i ? 2 : 3 == +i ? 3 : 5 == +i ? 4 : 4 == +i && "services_project" === e ? 5 : 4 == +i && "services_staff" === e ? 6 : 1;
        }
    }, {
        key: "$$linkNavigateTo",
        value: function(i) {
            if (!n.default.isEmptyObject(i) && void 0 !== i.modid) {
                i = 4 != +i.modid ? Object.assign(i, {
                    op: i.cid ? "link" : "view"
                }) : Object.assign(i, {
                    op: i.cid ? "link" : "view",
                    id: i.cid
                });
                var e = o.default.model, t = n.default.createModelUrl(e, i);
                wx.navigateTo({
                    url: t,
                    fail: function(i) {
                        console.error(i);
                    }
                });
            }
        }
    }, {
        key: "navigatImageLink",
        value: function(i) {
            var e = this, t = i.currentTarget.dataset, a = t.key, o = t.index;
            if ("view" === t.mode) {
                var d = this.options.scope, s = this.page.data["" + d].content[a].data.images, r = s[o], c = r.url, u = r.link;
                if (u) {
                    var l = u.sid, g = u.modid, h = u.navid, p = u.cardid, v = u.id, f = u.model, m = f.catid, w = f.cid, b = p ? "services_staff" : "services_project";
                    if ("linksite" === u.type) n.default.saveOriginSiteData(u.originsite).then(function() {
                        e.$$linkNavigateTo({
                            sid: l,
                            modid: g,
                            navid: h,
                            catid: m,
                            cid: w,
                            id: v,
                            caseid: w,
                            model: b
                        });
                    }, function() {}); else if ("linkapp" === u.type) {
                        if ("wxb6eef443a6b04494" === getApp().globalData.appid) return void wx.showModal({
                            title: "操作提示",
                            content: "小官网内暂不支持跳转至第三方小程序，请到授权独立小程序操作",
                            showCancel: !1,
                            confirmText: "我知道了"
                        });
                        var k = u.data, $ = k.redirectappid, T = k.appname;
                        $ && wx.navigateToMiniProgram({
                            appId: $,
                            fail: function(i) {
                                i.errMsg.indexOf("is not in navigateToMiniProgramAppIdList") > -1 && wx.showModal({
                                    title: "操作提示",
                                    content: '小程序-"' + T + '"暂未授权绑定，请前往PC端设置',
                                    showCancel: !1,
                                    confirmText: "我知道了"
                                });
                            }
                        });
                    } else this.$$linkNavigateTo({
                        sid: l,
                        modid: g,
                        navid: h,
                        catid: m,
                        cid: w,
                        id: v,
                        caseid: w,
                        model: b
                    });
                } else {
                    var x = s.map(function(i) {
                        return i.url;
                    });
                    wx.previewImage({
                        current: c,
                        urls: x
                    });
                }
            }
        }
    }, {
        key: "navigatLinkLink",
        value: function(i) {
            var e = this, t = i.currentTarget.dataset.params;
            if (t) {
                if (4 == +t.modid) {
                    var a = t, o = a.sid, d = a.modid, s = a.navid, r = a.id, c = a.cid, u = a.cardid, l = a.model.catid;
                    t = {
                        sid: o,
                        navid: s,
                        modid: d,
                        catid: l,
                        cid: c,
                        id: r,
                        model: u ? "services_staff" : "services_project"
                    };
                } else 5 == +t.modid && (t.caseid = t.cid);
                if (t.cid = t.cid || t.model.cid, "linksite" === t.type) n.default.saveOriginSiteData(t.originsite).then(function(i) {
                    e.$$linkNavigateTo(t);
                }, function() {}); else if ("linkapp" === t.type) {
                    if ("wxb6eef443a6b04494" === getApp().globalData.appid) return void wx.showModal({
                        title: "操作提示",
                        content: "小官网内暂不支持跳转至第三方小程序，请到授权独立小程序操作",
                        showCancel: !1,
                        confirmText: "我知道了"
                    });
                    var g = t.data, h = g.redirectappid, p = g.appname;
                    h && wx.navigateToMiniProgram({
                        appId: h,
                        fail: function(i) {
                            i.errMsg.indexOf("is not in navigateToMiniProgramAppIdList") > -1 && wx.showModal({
                                title: "操作提示",
                                content: '小程序-"' + p + '"暂未授权绑定，请前往PC端设置',
                                showCancel: !1,
                                confirmText: "我知道了"
                            });
                        }
                    });
                } else this.$$linkNavigateTo(t);
            }
        }
    }, {
        key: "openLocation",
        value: function(i) {
            var e = this, t = i.currentTarget.dataset;
            t.latitude && wx.openLocation({
                latitude: +t.latitude,
                longitude: +t.longitude,
                name: t.name,
                address: t.address,
                fail: function(i) {
                    return d.default.userLocation(i, function(i) {
                        return e.openLocation(i);
                    });
                }
            });
        }
    }, {
        key: "$$formatSwiperHeight",
        value: function(i) {
            var t = this.options.scope, a = this.page.data, n = a.windowWidth, o = a["" + t].content, d = i.index, s = o[d], r = a.swiper;
            if (r.indexOf(d) < 0) {
                r.push(d);
                var c = n * (i.imageHeight / i.imageWidth);
                s.height = c, this.page.setData(e({}, t + ".content[" + d + "]", s));
            }
        }
    }, {
        key: "imageLoad",
        value: function(i) {
            var e = {
                imageWidth: i.detail.width,
                imageHeight: i.detail.height,
                index: i.currentTarget.dataset.index
            };
            this.$$formatSwiperHeight(e);
        }
    }, {
        key: "playVideo",
        value: function(i) {
            var e = i.currentTarget.dataset.video, t = e.file, a = t.url, n = t.fieldid, o = e.content;
            this.page.setData({
                videoSource: a
            }), this.videoContext || (this.videoContext = wx.createVideoContext("editor_video")), 
            this.videoContext.seek(0), this.videoContext.requestFullScreen({
                direction: 0
            }), this.page.setData({
                "$$editor.video": {
                    content: o,
                    fieldid: n,
                    start: Date.now()
                }
            });
        }
    }, {
        key: "videoScreenchange",
        value: function(i) {
            i.detail.fullScreen ? this.videoContext.play() : (this.videoContext.pause(), this.page.setData({
                videoSource: ""
            }), this.__pushWatchVideoEvent());
        }
    }, {
        key: "__pushWatchVideoEvent",
        value: function() {
            var i = this, e = this.page.data.sidebar.site.sid, t = this.page.data.$$editor.video, a = t.content, o = void 0 === a ? "" : a, d = t.fieldid, s = t.start, r = Math.round((Date.now() - s) / 1e3);
            e && r && n.default.pushWatchVideoEvent(e, r, {
                fieldid: d,
                title: o
            }).then(function() {
                i.page.setData({
                    "$$editor.video": {}
                });
            }).catch(function() {
                i.page.setData({
                    "$$editor.video": {}
                });
            });
        }
    }, {
        key: "$$redirectToNavigation",
        value: function(i) {
            var e = i.currentTarget.dataset, t = e.key;
            if ("edit" === e.mode) wx.showModal({
                content: "编辑状态下无法跳转,请保存后再操作",
                showCancel: !1
            }); else {
                var a = this.page.data["" + this.options.scope].content[t].data.nav.nav, n = a.sid, o = a.modid, d = a.navid, s = a.catid;
                this.$$linkNavigateTo({
                    sid: n,
                    modid: o,
                    navid: d,
                    catid: s
                });
            }
        }
    }, {
        key: "$$redirectToDetail",
        value: function(i) {
            var e = i.currentTarget.dataset, t = e.key, a = e.index;
            if ("edit" === e.mode) wx.showModal({
                content: "编辑状态下无法跳转,请保存后再操作",
                showCancel: !1
            }); else {
                var o = this.page.data["" + this.options.scope].content[t].data.nav.list[a], d = o.sid, s = o.modid, r = o.navid, c = o.catid, u = o.cid, l = o.cardid, g = {
                    sid: d,
                    modid: s,
                    navid: r,
                    catid: c
                };
                if (4 == +s) {
                    var h = l ? "services_staff" : "services_project";
                    g = n.default.extend({}, g, {
                        model: h,
                        id: u,
                        op: "link"
                    });
                } else g = 5 == +s ? n.default.extend({}, g, {
                    caseid: u,
                    cid: u
                }) : n.default.extend({}, g, {
                    cid: u
                });
                this.$$linkNavigateTo(g);
            }
        }
    }, {
        key: "$$makePhoneCall",
        value: function(i) {
            var e = i.currentTarget.dataset.mobile;
            wx.makePhoneCall({
                phoneNumber: "" + e
            });
        }
    }, {
        key: "redirectToBargainingList",
        value: function() {
            var i = this.page.data.sidebar.site, e = i.sid, t = i.name;
            (0, s.askForSignin)() || wx.navigateTo({
                url: "/pages/common/bargaining/list/list?sid=" + e + "&name=" + t
            });
        }
    }, {
        key: "redirectToPayment",
        value: function() {
            var i = this.page.data.sidebar.site, e = i.sid, t = i.name;
            (0, s.askForSignin)() || wx.navigateTo({
                url: "/pages/common/payment/payment?sid=" + e + "&name=" + t
            });
        }
    }, {
        key: "redirectToCouponList",
        value: function() {
            var i = this.page.data.sidebar.site.sid;
            (0, s.askForSignin)() || wx.navigateTo({
                url: "/pages/common/coupon/list/list?sid=" + i
            });
        }
    }, {
        key: "redirectToGrouponList",
        value: function() {
            var i = this.page.data.sidebar.site, e = i.sid, t = i.name;
            (0, s.askForSignin)() || wx.navigateTo({
                url: "/pages/common/groupon/list/list?sid=" + e + "&name=" + t
            });
        }
    }, {
        key: "$$gotoRaffleList",
        value: function() {
            var i = this;
            if (!this.$$gotoRaffleing) {
                this.$$gotoRaffleing = !0;
                var e = this.page.data.sidebar.site.sid;
                return c.default.site.lottery.lists({
                    data: {
                        sid: e,
                        type: "starting",
                        limit: 3,
                        offset: 0
                    }
                }).then(function(t) {
                    i.$$gotoRaffleing = !1;
                    var a = t.lists;
                    1 === a.length ? wx.redirectTo({
                        url: "/pages/common/raffle/view/view?sid=" + e + "&lid=" + a[0].lid
                    }) : wx.navigateTo({
                        url: "/pages/common/raffle/raffle-list/raffle-list?sid=" + e
                    });
                }).catch(function() {
                    return i.$$gotoRaffleing = !1;
                });
            }
        }
    }, {
        key: "viewBargaining",
        value: function(i) {
            var e = i.currentTarget.dataset, t = e.id, a = e.index, n = this.page.data.sidebar.site.name;
            "edit" !== this.page.data.mode && wx.navigateTo({
                url: "/pages/common/bargaining/view/view?index=" + a + "&bargainid=" + t + "&name=" + n
            });
        }
    }, {
        key: "viewCard",
        value: function(i) {
            var e = getApp(), t = i.currentTarget.dataset.card, a = t.aid, n = t.cardid, o = t.guid, d = e.globalData.app;
            if ("edit" !== this.page.data.mode) if ("site" === d) wx.navigateToMiniProgram({
                appId: "wx252db2bdbbfccbc7",
                path: "pages/card/view/view?cardid=" + n + "&aid=" + a + "&guid=" + o
            }); else {
                var s = o ? "xmp" : "card", r = "";
                e.getTokens().then(function(i) {
                    var e = i.accesstoken;
                    r = "https://api.ibos.cn/v4/weappcard/showqrcode?accesstoken=" + e + "&app=" + s + "&cardid=" + n + "&t=" + Date.now(), 
                    wx.previewImage({
                        urls: [ r ]
                    });
                });
            }
        }
    }, {
        key: "viewGroupon",
        value: function(i) {
            var e = i.currentTarget.dataset, t = e.id, a = e.index, n = e.type, o = this.page.data.sidebar.site.name, d = +n ? "view/view" : "preview/preview";
            "edit" !== this.page.data.mode && wx.navigateTo({
                url: "/pages/common/groupon/" + d + "?index=" + a + "&grouponid=" + t + "&name=" + o
            });
        }
    }, {
        key: "viewPanorama",
        value: function(i) {
            var e = i.currentTarget.dataset.source;
            wx.navigateTo({
                url: "/pages/common/VR/view/view?source=" + e
            });
        }
    }, {
        key: "showProductBar",
        value: function(i) {
            var e = i.currentTarget.dataset.item, t = e.sid, a = e.navid, n = e.catid, o = e.cid;
            this.page.setData({
                shoppingcartInitData: {
                    sid: t,
                    navid: a,
                    catid: n,
                    cid: o
                }
            });
        }
    }, {
        key: "redirectToSearch",
        value: function() {
            var i = this.page.data.sidebar.site, e = i.sid, t = i.version;
            wx.navigateTo({
                url: "/pages/common/search/index/index?sid=" + e + "&version=" + t
            });
        }
    } ]), i;
}();

exports.default = u;